package net.zhengxinyun.performance.service.examNew;

import net.zhengxinyun.performance.Util.DateUtils;
import net.zhengxinyun.performance.dto.examDTO.ExamDTO;
import net.zhengxinyun.performance.entity.exam.PingyiEntity;
import net.zhengxinyun.performance.entity.exam.PyInqObjEntity;
import net.zhengxinyun.performance.filter.exam.PingyiFilter;
import net.zhengxinyun.performance.filter.exam.PyInqObjFilter;
import net.zhengxinyun.performance.mapper.examNew.PingyiEntityMapper;
import net.zhengxinyun.performance.mapper.examNew.PyInqObjEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Date: 2020/3/25 16:03
 * 公众评议
 */
@Service
public class PingYiServiceImpl implements PingYiService {
    @Autowired
    private PingyiEntityMapper mapper;

    @Autowired
    private PyInqObjEntityMapper pyobjMapper;

    /**
     * 公众评议管理
     * @param filter
     * @param optionType
     * @return
     */
    @Override
    public HashMap<String, Object> managePingYi(PingyiFilter filter, String optionType) {
       HashMap<String,Object> map =new HashMap();
                PingyiEntity record = new PingyiEntity();
                record.setDepartCode(filter.getDepartCode());
                record.setStartDate(filter.getStartDate());
                record.setEndDate(filter.getEndDate());
                record.setPyName(filter.getPyName());
                record.setQuestionnaireId(filter.getQuestionnaireId());
        switch (optionType){
            case "add":
                record.setId(null);
                filter.setCreateDate(DateUtils.getCurrentDateTime());
                mapper.insert(record);
                break;
            case "update":
                filter.setCreateDate(null);
                record.setId(filter.getPyId());
                mapper.updateByPrimaryKeySelective(record);

                break;
            case "del":

                mapper.deleteByPrimaryKey(filter.getPyId());
                break;
            case "query":

                PingyiFilter filter2 = new PingyiFilter();
                List<PingyiFilter> pingyiFilters = selectListPingYis(filter2);
                map.put("data",pingyiFilters);
                return map;
        }
        map.put("code",200);
        return map;
    }





    @Override
    public List<PingyiFilter> selectListPingYis(PingyiFilter filter) {
        return mapper.selectListPYlists(filter);
    }


    /**
     * 公众评议对象的管理
     * @return
     */
    @Override
    public HashMap<String, Object> managePYObj(String optionTYpe, PyInqObjFilter filter) {
       // String optionType = filter.getOptionType();
        PyInqObjEntity record = new PyInqObjEntity();
        record.setInqId(filter.getInqId());
        record.setPyId(filter.getPyId());

        switch (optionTYpe){
            case "add":
                record.setId(null);
                pyobjMapper.insert(record);

                break;
            case "update":
                record.setId(filter.getPyObjId());

                pyobjMapper.updateByPrimaryKeySelective(record);
                break;
            case "del":
                pyobjMapper.deleteByPrimaryKey(filter.getPyObjId());
                break;
            case "query":
                List<PyInqObjFilter> lists = pyobjMapper.selectPYObjs(filter);

                HashMap<String,Object> map =  new HashMap<>();
                map.put("data",lists);
                return map;
        }

        return null;
    }

    /**
     * 条件查询调查对象
     * @param filter
     * @return
     */
    @Override
    public List<PyInqObjFilter> selectListPYobjs(PyInqObjFilter filter){

        List<PyInqObjFilter> pyInqObjFilters = pyobjMapper.selectPYObjs(filter);
        return pyInqObjFilters;
    }

    @Override
    public List<ExamDTO> getPYInfos(ExamDTO dto) {

        List<ExamDTO> examDTOS = pyobjMapper.selectPyinfos(dto);

        return examDTOS;
    }
}
